home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Configuration_En / Commands / InsertOfficeDoc.js < prev    next >
Encoding:
Text File  |  2003-07-18  |  3.0 KB  |  125 lines

  1. //=========================================================================================================
  2. //
  3. // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
  4. //
  5. // Feature: Paste Fix
  6. // Author:  JDH
  7. // Module:  InsertOfficeDoc.js
  8. // Purpose:    Insert Office Document menu item handler.
  9. // Updates:
  10. //    8/1/02 - Started file control
  11. //
  12. //=========================================================================================================
  13.  
  14.     // The threshold where we should warn the user they are importing a big file
  15.  
  16. MM.od_WarnThreshold = 100000;
  17.  
  18.     // The threshold where we should not allow the user to import the file.
  19.  
  20. MM.od_MaxThreshold = 200000;
  21.  
  22. var g_file = null;
  23. var g_retVal = null;
  24.  
  25. function receiveArguments()
  26. {
  27.     g_file = arguments[0];
  28.     g_retVal = arguments[1];
  29. }
  30.  
  31. function run()
  32. {
  33.     var insertedAnything = insertOfficeDoc( g_file );
  34.     if (g_retVal)
  35.         g_retVal[0] = insertedAnything;
  36. }
  37.  
  38. // insertOfficeDoc - Inserts the given file name into the current document.
  39. function insertOfficeDoc( file )
  40. {
  41.     // ensure it's a convertible office doc. if not, punt.
  42.     if (!dw.isOfficeDocument(file, true))
  43.     {
  44.         alert(dw.loadString("insert doc dialog/not office doc error"));
  45.         return false;
  46.     }
  47.  
  48.     var insertedAnything = false;
  49.  
  50.     // Switch on Excel or Word.  Use one of those to open up the file, and
  51.     // to save the contents as HTML and return it.
  52.  
  53.     var usedWord = false;
  54.  
  55.     var result;
  56.     if ( file.match( /[.]xls/i ) )
  57.     {
  58.         result = dw.excelSaveAsHTML( file );
  59.     }
  60.     else
  61.     {
  62.         result = dw.wordSaveAsHTML( file );
  63.         usedWord = true;
  64.     }
  65.  
  66.     // Get the text and the base URL
  67.  
  68.     var text = result[ 0 ];
  69.     var url = result[ 1 ];
  70.  
  71.     // Go through a bunch of logic to warn or alert the user to large files,
  72.     // and either insert it or not
  73.  
  74.     if ( text != null && text.length > 0 )
  75.     {
  76.         if ( text.length < MM.od_WarnThreshold )
  77.         {
  78.             dw.getDocumentDOM().pasteInHTML( text, url );
  79.             insertedAnything = true;
  80.         }
  81.         else if ( text.length < MM.od_MaxThreshold )
  82.         {
  83.             var retVal = confirm( MM.MSG_odWarnWithLink );
  84.             if ( retVal == true )
  85.             {
  86.                 dw.getDocumentDOM().pasteInHTML( text, url );
  87.                 insertedAnything = true;
  88.             }
  89.             else
  90.             {
  91.                 var dropResult = [ false ];
  92.                 /*const*/ var allowInsertContents = false;
  93.                 /*const*/ var rememberPrefs = false;
  94.                 dw.runCommand("DropOffice2.htm", file, dropResult, allowInsertContents, rememberPrefs);
  95.                 insertedAnything = dropResult[0];
  96.             }
  97.         }
  98.         else
  99.         {
  100.             alert( MM.MSG_odStopWithLink );
  101.  
  102.             var dropResult = [ false ];
  103.             /*const*/ var allowInsertContents = false;
  104.             /*const*/ var rememberPrefs = false;
  105.             dw.runCommand("DropOffice2.htm", file, dropResult, allowInsertContents, rememberPrefs);
  106.             insertedAnything = dropResult[0];
  107.         }
  108.     }
  109.     else
  110.     {
  111.         if ( usedWord )
  112.         {
  113.             alert( MM.MSG_odWordUnableToSaveAs );
  114.             insertedAnything = true;
  115.         }
  116.         else
  117.         {
  118.             alert( MM.MSG_odExcelUnableToSaveAs );
  119.             insertedAnything = true;
  120.         }
  121.     }
  122.  
  123.     return insertedAnything;
  124. }
  125.